'''
在单元格中 定位数据

'''

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class DataLocation(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.setWindowTitle("QtableWidget Kongjian")
        self.resize(600, 800)
        layout = QHBoxLayout()
        tableWidget = QTableWidget()
        tableWidget.setRowCount(40)
        tableWidget.setColumnCount(4)

        # layout.addWidget(tableWidget)

        for i in range(40):
            for j in range(4):
                itemContent = '(%d-%d)'%(i, j)
                tableWidget.setItem(i, j, QTableWidgetItem(itemContent))

        # find data
        text = '(13-1)'
        items = tableWidget.findItems(text, Qt.MatchExactly)
        if len(items)>0:
            item = items[0]
            item.setBackground(QBrush(QColor(0, 255, 0)))
            item.setForeground(QBrush(QColor(255, 0, 0)))
            row = item.row()
            tableWidget.verticalScrollBar().setSliderPosition(row)
        layout.addWidget(tableWidget)
        self.setLayout(layout)

if __name__ == '__main__':

    app = QApplication(sys.argv)

    ex = DataLocation()
    ex.show()
    sys.exit(app.exec_())